package com.ktjy.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ktjy.pojo.SysUser;
import com.ktjy.mapper.SysUserMapper;
import com.ktjy.service.ISysUserService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author hjy
 * @since 2025-01-09
 */
@Service
public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> implements ISysUserService {
    @Autowired
    SysUserMapper sysUserMapper;

    @Override
    public SysUser login(String usrName, String usrPassword) {
        QueryWrapper<SysUser> qw = new QueryWrapper<>();
        qw.eq("usr_name", usrName);

        SysUser sysUser=sysUserMapper.selectOne(qw);
        if(sysUser!=null){
            if (sysUser.getUsrPassword().equals(usrPassword)){
                return sysUser;
            }
        }
        return null;
    }

    @Override
    public IPage<SysUser> getPage(SysUser sysUser,Integer pageNo,Integer pageSize) {
        Page page=new Page(pageNo,pageSize);
        Map<String,Object> map=new HashMap<>();
        map.put("usrRoleId",sysUser.getUsrRoleId());
        map.put("usrName",sysUser.getUsrName());
        return sysUserMapper.getPage(page,map);
    }
}
